# 定义可执行文件和LaTeX输出文件
EXECUTABLES = A B C Curvefitting E F test
PDFS = doc/report.pdf doc/design.pdf

# 默认目标 - 编译所有C++程序和LaTeX文档并运行它们，最后清理中间文件
all: $(EXECUTABLES) $(PDFS) clean

# 编译并运行C++文件的规则
A: src/A.cpp
	g++ -o $@ $< && ./$@

B: src/BSplines_test.cpp
	g++ -o $@ $< && ./$@

C: src/C.cpp
	g++ -o $@ $< && ./$@

Curvefitting: src/Curvefitting.cpp
	g++ -o $@ $< -lmuparser && ./$@

E: src/E.cpp
	g++ -o $@ $< && ./$@

F: src/F.cpp
	g++ -o $@ $< && ./$@

test: src/test.cpp
	g++ -o $@ $< && ./$@

# 编译LaTeX文件

doc/report.pdf: doc/report.tex
	xelatex -output-directory=doc $<
	xelatex -output-directory=doc $<
	xelatex -output-directory=doc $<
doc/design.pdf: doc/design.tex
	xelatex -output-directory=doc $<
	xelatex -output-directory=doc $<
	xelatex -output-directory=doc $<


# 运行所有程序的目标
run_all: $(EXECUTABLES) $(PDFS) 
	@echo "Running all C++ programs..."
	$(foreach exe,$(EXECUTABLES),./$(exe);)
	@echo "All programs have been run."

# 清理中间文件，包括所有的 .txt, .gp, .plt, 和 .dat 文件
clean:
	rm -f $(EXECUTABLES) doc/*.log doc/*.aux *.bbl *.blg *.txt doc/*.txt *.gp *.plt *.dat doc/*.gp doc/*.plt doc/*.dat doc/*.out doc/*.toc

.PHONY: all clean run_all